<template>
	<view class="page">
		<view class="head-back">
			<view class="back" @click="onBack">
				<text></text>
			</view>
			<view class="title">
				<text>我的订单</text>
			</view>
			<view class="more-icon">
				<view class="icon-list">
					<text class="iconfont icon-fadajing"></text>
				</view>
			</view>
		</view>
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" :class="{'action':OrderType==6}" @click="onOrderTab(6)">
				<text>全部</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==0}" @click="onOrderTab(0)">
				<text>待付款</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==1}" @click="onOrderTab(1)">
				<text>待发货</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==2}" @click="onOrderTab(2)">
				<text>待收货</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==3}" @click="onOrderTab(3)">
				<text>待评价</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="list" v-for="(item,index) in orderlist" @click="onOrderList(item.id)" :key="index">
				<view class="title-status">
					<view class="title">
						<text>下单时间：{{item.createTime}}</text>
					</view>
					<view class="status">
						<text>{{item.status}}</text>
						<text class="iconfont icon-laji del"></text>
					</view>
				</view>
				<view class="goods-list" v-for="i in item.cgoOrderGoodsList">
					<view class="goods">
						<view class="thumb">
							<image :src="'/static/img/goods_thumb_0'+(index+1)+'.png'" mode=""></image>
						</view>
						<view class="item">
							<view class="goods-name">
								<text class="two-omit">{{i.goodsName}}</text>
							</view>
							<view class="goods-price">
								<text class="min">￥</text>
								<text class="max">{{i.goodsPrice}}</text>
								<text class="min"></text>
							</view>
						</view>
					</view>
				</view>
				<view class="status-btn">
					<view v-if='item.statusID == 2'>
						<view class="btn action" @click.stop="onEvaluate(2,item.id,item.actualPrice)">
							<text>确认收货</text>
						</view>
					</view>
					<view v-if='item.statusID == 0'>
						<view class="btn action" @click.stop="onEvaluate(0,item.id,item.actualPrice)">
							<text>去付款</text>
						</view>
					</view>
					<view v-if='item.statusID == 1'>
						<view class="btn action" @click.stop="onEvaluate(1,item.id,item.actualPrice)">
							<text>正在发货</text>
						</view>
					</view>
					<view v-if='item.statusID == 3'>
						<view class="btn action" @click.stop="onEvaluate(3,item.id,item.actualPrice)">
							<text>评价</text>
						</view>
					</view>
					<view v-if='item.statusID == 4'>
						<view class="btn action" @click.stop="onEvaluate(4,item.id,item.actualPrice)">
							<text>删除订单</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import axios from 'axios'
	export default {
		data() {
			return {
				OrderType: 6,
				userid: 0,
				orderlist: [],
			};
		},
		onLoad(params) {
			if (params.type != null && params.type != undefined) {
				this.OrderType = params.type;
			}
			return
		},
		created() {
			axios.request("http://localhost:8089/order/status/" + this.OrderType + "/" + this.userid).then(
				res => {
					this.orderlist = res.data;
					console.log(this.orderlist)
				}
			)
		},
		methods: {
			/**
			 * 返回点击
			 */
			onBack() {
				uni.navigateBack();
			},
			/**
			 * 订单tab点击
			 */
			onOrderTab(type) {
				this.OrderType = type;
				// #ifdef H5
				uni.redirectTo({
					url: '/pages/MyOrderList/MyOrderList?type=' + type,
				})
				//#endif
			},
			/**
			 * 订单列表点击
			 */
			onOrderList(orderid) {
				uni.navigateTo({
					url: '/pages/OrderDetails/OrderDetails?id=' + orderid,
				})
			},
			/**L
			 * 评价点击
			 */
			onEvaluate(id,orderid,zong) {
				if (id == 0) {
					uni.redirectTo({
						 url: '/pages/CashierDesk/CashierDesk?id='+orderid+'&zong='+zong
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'MyOrderList.scss';
</style>
